<template>
  <div class="current-page">
    <el-row class="yngsds">
      <el-col style="display: flex; justify-content: flex-end">
        <el-button type="primary" icon="el-icon-search" @click="shuaxuhs">刷新</el-button>
      </el-col>
    </el-row>
    <com-table ref="comTable" :tableData="tableData" url="system/log/local" keyName="XPRO_ARRAY" :has-data="hasData"
      :table-head-list="tableHeadList" :total-count="totalCount" :page-num="pageNum" :searchForm="identform"
      :page-size="pageSize" :page-sizes="pageSizes" :table-loading="loading" :table-height="tableHeight"
      :is-show-select="true" :page-show="false" :handle-show="hadnsholes" :merge-flag="false" :baddxtsd="true"
      @chooseData="chooseData" @cobnabagsata="cobnabagsata" @setSearchHeight="setTableHeight">
    </com-table>
    <!-- 新增 -->
    <el-dialog :title="usbkebang" :visible="showAuditDialog" @close="showAuditDialog = false"
      custom-class="alarm-type-detail el-dialog-widthSmall" :close-on-click-modal="false" @closed="auditDialogClosed">
      <div class="dengshus">
        <el-form label-width="80px" :model="formInline">
          <div class="awas">
            <el-form-item label="序列号">
              <el-input v-model="formInline.KeySerial" placeholder="请输入序列号"></el-input>
            </el-form-item>
          </div>
          <div class="awas">
            <el-form-item label="类型">
              <el-input v-model="formInline.KeyType" placeholder="请选择类型"></el-input>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showAuditDialog = false">取 消</el-button>
        <el-button type="primary" @click="confirmInfo">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 绑定用户/绑定终端 -->
    <el-dialog title="绑定用户/绑定终端" :visible="showDetailinagbangd" @close="showDetailinagbangd = false"
      custom-class="equip-detail el-dialog-widthMiddle" width="30%" @closed="bangdliangshu">
      <div>
        <el-button type="primary" @click="bangdying">绑定用户</el-button>
        <el-button type="primary" @click="bnagsdzhus">绑定终端</el-button>
      </div>
    </el-dialog>
    <!-- 绑定 -->
    <el-dialog title="绑定用户" :visible="showDetailDialog" @close="showDetailDialog = false"
      custom-class="equip-detail el-dialog-widthMiddle" width="60%" @closed="bangdingdalogs">
      <div>
        <el-form label-width="140px" :model="identform">
          <el-row class="danhus">
            <el-col :span="18">
              <el-form-item label="输入KEY PIN码">
                <el-input placeholder="请输入KEY PIN码" type="password" v-model="identform.keyId" clearable
                  show-password></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <p class="yihangs">注意：PIN码输入错误达到一定次数，USBKey将锁定</p>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="认证模式">
                <el-radio v-model="radio" label="1">多因子认证</el-radio>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="认证因子">
                <el-checkbox v-model="identform.bindFactor">终端账户密码</el-checkbox>
                <el-checkbox v-model="identform.bindFactor1">PIN码</el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="终端账户绑定">

              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="18">
              <el-form-item label="责任人">
                <el-select v-model="identform.empUserName" placeholder="请选择责任人">
                  <el-option v-for="item in emonamse" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="danhus">
            <el-col :span="18">
              <el-form-item label="终端账户">
                <el-select v-model="identform.user" placeholder="请选择">
                  <el-option v-for="item in userlist" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <p class="yihangs">说明：系统账号绑定后，下次登录需要插入USBKey才能完成</p>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showDetailDialog = false">关 闭</el-button>
        <el-button type="primary" @click="bangdinque">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="绑定终端" :visible="showbangzduanlog" @close="showbangzduanlog = false"
      custom-class="equip-detail el-dialog-widthMiddle" width="60%" @closed="bangdlzhongduas">
      <div class="zhondbsts">
        <div class="shaixun">
          <span>操作系统账号 </span>
          <el-select v-model="xitzhanghso" placeholder="请选择">
            <el-option v-for="item in xitzhanlsit" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="sous">
          <el-input v-model="rganization" placeholder="请输入关键字"></el-input>
          <el-button type="primary">高级搜索</el-button>
        </div>
        <div class="baiosh">
          <el-table :data="tableData" style="width: 100%" @select="handleSelectizuhi" @select-all="handleSelectizuhi"
            @selection-change="handleSelectizuhi" :default-sort="{ prop: 'date', order: 'descending' }">
            <el-table-column type="selection" :reserve-selection="true" align="center"></el-table-column>
            <el-table-column prop="KeySerial" label="序号" width="120">
            </el-table-column>
            <el-table-column prop="DevIP" label="终端名称" sortable>
            </el-table-column>
            <el-table-column prop="UserName" label="终端唯一标识" sortable>
            </el-table-column>
            <el-table-column prop="FullDeptName" label="ip地址" sortable>
            </el-table-column>
            <el-table-column prop="FullDeptName" label="绑定状态" sortable>
            </el-table-column>
            <el-table-column prop="FullDeptName" label="系统类型" sortable>
            </el-table-column>
          </el-table>
          <el-pagination background :page-sizes="[5, 10, 20, 100]" :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="totalCount"
            style="text-align: center; margin-top: 10px" @size-change="handleSizeChange"
            @current-change="handlePageChange">
          </el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showbangzduanlog = false">关 闭</el-button>
        <el-button type="primary" @click="zhonduqures">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 解绑终端 -->
    <el-dialog title="解绑用户/解绑终端" :visible="showjiebangsz" @close="showjiebangsz = false"
      custom-class="equip-detail el-dialog-widthMiddle" width="30%" @closed="showjiebansgsdsz">
      <div class="jiebangzhong">
        <el-button type="primary" @click="butzbangds('1')">解绑用户</el-button>
        <el-button type="primary" @click="butzbangds('2')">解绑终端</el-button>
      </div>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="showjiebangsz = false">关 闭</el-button>
        <el-button type="primary" @click="jiebangques">确 定</el-button>
      </span> -->
    </el-dialog>
  </div>
</template>
<script>
import QS from "qs";
import ComTable from "../../components/table/comTable";
export default {
  name: "USBkeyAdmin",
  data() {
    return {
      accountNameOnline: "",
      pageNum: 1, // 当前页
      pageSize: 10,
      empIds: "",
      empNames: "",
      pageSizes: [5, 10, 20, 100],
      totalCount: 0, //共多少条数据
      tableHeight: "", // 表格高度
      hasData: true,
      showjiebangsz: false,
      identform: {
        keyId: "",
        bindFactor: "",
        bindFactor1: true,
        user: "",
        empUserName: "",
        empUser: "",
      },
      importAdminControl: false,
      tableHeadList: [
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "Key序列号",
          columnName: "keyId",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "绑定状态",
          columnName: "status",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "账号",
          columnName: "empUserAccount",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "姓名",
          columnName: "empUserName",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "系统账号",
          columnName: "user",
        },
      ],
      tableData: [],
      formInline: {
        KeySerial: "",
        KeyType: "",
      },
      userlist: [],
      rganization: "", //组织机构
      loading: false, // 数据加载状态遮罩
      dialogTitle: "",
      showbangzduanlog: false, // 绑定zhonduan
      showAuditDialog: false, //新增
      showDetailDialog: false, // 绑定用户
      showDetailinagbangd: false,
      multipleSelection: [],
      datasLisdt: [
        {
          label: "一级 1",
          children: [
            {
              label: "二级 1-1",
              children: [
                {
                  label: "三级 1-1-1",
                },
              ],
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      testBindData: [
        {
          keyId: "E56EE0790C02327C",
          keyType: "273",
          user: "bright",
          onlyId: "c3adhsadk4jbldjvhlakvjhkal",
          empUser: "sdt123",
          empUserName: "xxx",
          status: "0",
        },
        {
          keyId: "E66EE0790C02327C",
          keyType: "273",
          user: "bright",
          onlyId: "c3adhsadk4jbldjvhlakvjhkal",
          empUser: "sdt123",
          empUserName: "xxx",
          status: "0",
        },
      ],
      testBindDatas: [
        {
          keySn: "329DCC736C12DDBB",
          keyType: "273",
          leftRetry: "0",
          keyName: "安全保密管理员",
        },
        {
          keySn: "202002125512",
          keyType: "273",
          leftRetry: "5",
          keyName: "user",
        },
        {
          keySn: "E66EE0790C02327C",
          keyType: "273",
          leftRetry: "5",
          keyName: "user",
        },
      ],
      xitzhanghso: "",
      xitzhanlsit: [],
      pageType: "1",
      usbkebang: "",
      absopindlosa: false,
      formpinsxe: {},
      checked: false,
      checked1: false,
      value: "",
      options: "",
      emonamse: [],
      hadnsholes: false,
      bangdrow: {},
      radio: "1",
      xulits: "",
      timestamp: "", //时间戳
    };
  },
  components: {
    ComTable,
  },
  created() {
    this.userName = window.sessionStorage.getItem("userName");
    console.log(this.userName);
    if (this.userName == "secadm" || this.userName == "admin") {
      this.hadnsholes = true;
    }
    this.timestamp = new Date().getTime();
    this.setTableHeight();
    // this.sjslogdrlist(result)
    // this.datalists();
    this.getHostInfo()
    // this.emzenr();
    // this.zhnahus();
    // this.zhonduid()
  },
  methods: {
    getHostInfo () {
      this.$get(`/vgmp/config/gethostinfo`).then((res) => {
        console.log(res.data.data);
        this.empIds = res.data.data.empID
        this.empNames = res.data.data.empName
        this.getUserData()
      });
    },
    //获取账户
    getUserData() {
      this.$get("/aqdl/user/getloginuser").then((res) => {
        console.log(res);
        this.accountNameOnline = res.data.data
        this.datalists();
      });
    },
    // 先调记录日志接口
    sjslogdrlist(result) {
      let eTimes = (new Date().getTime()+ '').substring(0, 10)
      console.log(eTimes, "Timestamp")
      let that = this;
      let KeySerial = '- -'
      this.$get("/aqdl/key/list_key").then(res => {
        console.log(res)
        if (res.data.data.keyArray.length != 0) {
          KeySerial = res.data.data.keyArray[0].keySn
        }
        let daJson = {
        "Root": {
          "LogType": "50",
          "LogRecord": {
            "Timestamp": eTimes + '',
            "EmpID": this.empIds,
            "EmpName": this.empNames,
            "Type": "321",
            "KeySerial": KeySerial,
            "KeyType": "273",
            "Account": this.accountNameOnline,
            "Role": "admin",
            "Result": result,
            "ResultDesc": result == "0" ? "成功" : "失败",
          },
        },
      };
      let daJsons = {
        "Root": {
          "LogType": "50",
          "LogRecord": {
            "Timestamp": eTimes + '',
            "EmpID": this.empIds,
            "EmpName": this.empNames,
            "Type": "322",
            "KeySerial": KeySerial,
            "KeyType": "273",
            "Account": this.accountNameOnline,
            "Role": "admin",
            "Result": result,
            "ResultDesc": result == "0" ? "成功" : "失败",
          },
        },
      };
      let daJsons1 = {
        "Root": {
          "LogType": "50",
          "LogRecord": {
            "Timestamp": eTimes + '',
            "EmpID": this.empIds,
            "EmpName": this.empNames,
            "Type": "322",
            "KeySerial": KeySerial,
            "KeyType": "273",
            "Account": this.accountNameOnline,
            "Role": "user",
            "Result": result,
            "ResultDesc": result == "0" ? "成功" : "失败",
          },
        },
      };
      that.$postForJson("/aqdl/auditlog/setlogrecord", daJson).then((res) => {
        console.log(res);
        that.$postForJson("/aqdl/auditlog/setlogrecord", daJsons).then((res) => {
          console.log(res);
          // that.zhonduid();
          that.$postForJson("/aqdl/auditlog/setlogrecord", daJsons1).then((res) => {
            console.log(res);
          });
        });
      });
      })
    },
    //10位时间戳转换
    getLocalTime(nS) {
      let time = new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ').replace(/\//g, '-');
      // 找出出现空格的位置
      let space_position = time.indexOf(' ');
      // 截取并返回数据
      return time.slice(0, space_position);
    },
    getBindData() {
      let that = this;
      //请求责任人
      this.$get("/aqdl/bjtx/list_user").then((res) => {
        this.emonamse = [];
        console.log(res);
        res.data.data.userArray.forEach((item) => {
          this.emonamse.push({
            label: item.name,
            value: item,
          });
        });
        //账户
        this.$get("/aqdl/bjtx/getlocalaccount").then((res) => {
          that.zhonduid();
          console.log(res);
          this.userlist = [];
          res.data.data.userArray.forEach((item) => {
            this.userlist.push({
              label: item,
              value: item,
            });
          });
        });
      });
    },
    datalists() {
      let that = this;
      this.$get("/aqdl/key/list_key").then((res) => {
        console.log(res, "list_key");
        let listKey = res.data.data.keyArray;
        this.$get("/aqdl/bjtx/list_bind")
          .then((res) => {
            if (res.data.data.bindArray) {
              // that.sjslogdrlist("0");
            } else {
              // that.sjslogdrlist("1");
            }
            // that.zhonduid();
            console.log(res, "list_bind");
            let listBind = res.data.data.bindArray;
            let listBindLength = parseInt(res.data.data.bindArray.length);
            if (listBindLength == 0) {
              listKey.forEach((item) => {
                item.keyId = item.keySn;
                item.status = "未绑定";
              });
              this.tableData = listKey;
              this.totalCount = parseInt(listKey.length);
            } else {
              listBind.forEach((item) => {
                if (item.status == "0") {
                  item.status = "正常";
                } else if (item.status == "1") {
                  item.status = "挂失";
                } else if (item.status == "2") {
                  item.status = "解绑";
                }
              });
              listKey.forEach((item) => {
                for (let i = 0; i < listBindLength; i++) {
                  if (item.keySn == listBind[i].keyId) {
                    break;
                  } else {
                    if (i == listBindLength - 1) {
                      item.keyId = item.keySn;
                      item.status = "未绑定";
                      listBind.push(item);
                    }
                  }
                }
              });
              this.tableData = listBind;
              this.totalCount = parseInt(listBind.length);
              console.log(this.tableData, "listBind");
            }
          })
          .catch((err) => {
            // that.sjslogdrlist("1");
          });
      });
    },
    shuaxuhs() {
      this.datalists();
    },
    headerCellStyle({ row, column, rowIndex, columnIndex }) {
      return {
        "font-size": "14px",
        "font-weight": 600,
        color: "#606266",
      };
    },
    // 请求责任人
    // emzenr() {
    //   this.$get("/aqdl/bjtx/list_user").then((res) => {
    //     console.log(res);
    //     res.data.data.userArray.forEach((item) => {
    //       this.emonamse.push({
    //         label: item.name,
    //         value: item,
    //       });
    //     });
    //   });
    // },
    // 账户
    // zhnahus() {
    //   this.$get("/aqdl/bjtx/getlocalaccount").then((res) => {
    //     console.log(res);
    //     res.data.data.userArray.forEach((item) => {
    //       this.userlist.push({
    //         label: item,
    //         value: item,
    //       });
    //     });
    //   });
    // },
    // 终端唯一id
    zhonduid() {
      this.$get("/vgmp/config/getserialnumber").then((res) => {
        console.log(res.data.data.data);
        this.xulits = res.data.data.data;
      });
    },
    // 选中项发生变化
    handleSelectionChange(val) {
      console.log(val, 246);
      this.multipleSelection = val;
    },
    handleSelectizuhi(val) {
      console.log(val);
    },
    // 新增
    clixingods(daa) {
      console.log(daa);
      if (daa == "add") {
        this.usbkebang = "USBKey新增";
      } else {
        this.usbkebang = "USBKey修改";
      }
      this.showAuditDialog = true;
    },
    // 新增确认
    confirmInfo() {
      this.showAuditDialog = false;
    },
    /**
     * 关闭对话框dialog
     */
    auditDialogClosed() {
      this.showAuditDialog = false;
    },
    bangdingdalogs() {
      this.showDetailDialog = false;
      this.identform = {
        keyId: "",
        bindFactor: "",
        bindFactor1: true,
        user: "",
        empUserName: "",
        empUser: "",
      };
    },
    // 获取
    bargainMoney() {
      this.$get("/aqdl/policy/getcontext?type=25").then((res) => {
        console.log(res);
        this.forinsm = res.data.data.policy[0].context.Root;
        let data = res.data.data.policy[0].context.Root;

        if (data.Complex == "3") {
          this.pinNews = new RegExp(
            `^(?=.*\\d)(?=.*[a-zA-Z])[\\da-zA-Z]{${this.forinsm.PINLengthS},${this.forinsm.PINLengthE}}$`, 'i'
          );
          this.pinmessa = `PIN码长度为${this.forinsm.PINLengthS}到${this.forinsm.PINLengthE}，PIN码包含字母和数字`;
        } else if (data.Complex == "5") {
          this.pinNews = new RegExp(
            "^(?=.*[a-zA-Z])(?=.*[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？])[a-zA-Z`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]" + `{${this.forinsm.PINLengthS},${this.forinsm.PINLengthE}}$`, 'i'
          );
          this.pinmessa = `PIN码长度为${this.forinsm.PINLengthS}到${this.forinsm.PINLengthE}，PIN码包含字母和特殊符号`;
        } else if (data.Complex == "6") {
          this.pinNews = new RegExp(
            "^(?=.*\\d)(?=.*[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？])[\\d`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]" + `{${this.forinsm.PINLengthS},${this.forinsm.PINLengthE}}$`
          );
          this.pinmessa = `PIN码长度为${this.forinsm.PINLengthS}到${this.forinsm.PINLengthE}，PIN码包含数字和特殊符号`;
        } else if (data.Complex == "7") {
          this.pinNews = new RegExp(
            "^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？])[\\da-zA-Z`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]" + `{${this.forinsm.PINLengthS},${this.forinsm.PINLengthE}}$`, 'i'
          );
          this.pinmessa = `PIN码长度为${this.forinsm.PINLengthS}到${this.forinsm.PINLengthE}，PIN码包含字母数字和特殊符号`;
        } else if (data.Complex == "1") {
          this.pinNews = new RegExp(
            `^[a-z]{${this.forinsm.PINLengthS},${this.forinsm.PINLengthE}}$`, 'i'
          );
          this.pinmessa = `PIN码长度为${this.forinsm.PINLengthS}到${this.forinsm.PINLengthE}的字母`;
        } else if (data.Complex == "2") {
          this.pinNews = new RegExp(
            `^\\d{${this.forinsm.PINLengthS},${this.forinsm.PINLengthE}}$`
          );
          this.pinmessa = `PIN码长度为${this.forinsm.PINLengthS}到${this.forinsm.PINLengthE}的数字`;
        } else if (data.Complex == "4") {
          this.pinNews = new RegExp(
            "^[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]" + `{${this.forinsm.PINLengthS},${this.forinsm.PINLengthE}}$`
          );
          this.pinmessa = `PIN码长度为${this.forinsm.PINLengthS}到${this.forinsm.PINLengthE}的特殊符号`;
        }
        console.log(this.identform.keyId);
        if (
          this.identform.keyId == null ||
          String(this.identform.keyId).trim() === ""
        ) {
          this.$message({
            message: "不能为空",
            type: "warning",
          });
        } else if (!this.pinNews.test(this.identform.keyId)) {
          this.$message({
            message: "pin码复杂度不符合要求,请先修改pin码",
            type: "warning",
          });
          this.showDetailDialog = false
        } else {
          this.clikqus()
        }
      });
    },
    // 绑定用户确定
    bangdinque() {
      let json = {
        keySerial: {
          keySn: this.bangdrow.keySn,
          keyType: this.bangdrow.keyType,
        },
        pinInfo: {
          type: "2",
          pin: this.identform.keyId,
        },
      };
      this.$postForJson("/aqdl/key/verify_pin", json).then((res) => {
        console.log(res.data.errorcode);
        if (res.data.errorcode != 0) {
          this.$message({
            message: "请输入正确的pin码",
            type: "warning",
          });
          // this.setlogrlist("296", res.data.errorcode, "失败");
        } else {
          // this.setlogrlist("296", res.data.errorcode, "成功");
          this.bargainMoney();
        }
      });
    },
    // 用户确定
    clikqus() {
      let data = {
        bindMode: "1",
        bindFactor: "1",
        keyId: this.bangdrow.keyId,
        keyType: this.bangdrow.keyType,
        user: this.identform.user,
        onlyId: this.xulits,
        empUser: this.identform.empUserName.empId,
        empUserAccount: this.identform.empUserName.account,
        empUserName: this.identform.empUserName.name,
        status: this.bangdrow.status == "未绑定" ? "0" : this.bangdrow.status,
      };
      this.$postForJson("/aqdl/bjtx/bind", data).then((res) => {
        console.log(res);
        if (res.data.errorcode == 0) {
          this.$message({
            message: "绑定成功！",
            type: "success",
          });
          this.setlogrlist("292", res.data.errorcode, "成功");
        } else {
          this.$message({
            message: "绑定失败！",
            type: "error",
          });
          this.setlogrlist("292", res.data.errorcode, "失败");
        }
        // this.datalists();
        this.identform = {};
      });
      this.showDetailDialog = false;
    },
    handleNodeClick(data) {
      console.log(data);
    },
    // 绑定
    chooseData(val, row) {
      if (row.status == "未绑定") {
        console.log(val, row);
        // this.showDetailinagbangd = val;
        this.showDetailDialog = val;
        this.getBindData();
        this.bangdrow = row;
      } else {
        this.$message({
          message: "不得重复绑定!",
          type: "warning",
        });
        return false;
      }
    },
    // 记录操作日志接口
    setlogrlist(tyid, sults, redusl) {
      let eTimes = (new Date().getTime()+ '').substring(0, 10)
      console.log(eTimes, "Timestamp")
      let that = this
      let KeySerial = '- -'
      // this.$get("/aqdl/bjtx/list_bind").then(res => {
      //   console.log(res)
      //   if (res.data.data.bindArray.length != 0) {
      //     KeySerial = res.data.data.bindArray.length[0].keyId
      //   }
      // })
      this.$get("/aqdl/key/list_key").then(res => {
        console.log(res)
        if (res.data.data.keyArray.length != 0) {
          KeySerial = res.data.data.keyArray[0].keySn
        }
        let daJson = {
        "Root": {
          "LogType": "50",
          "LogRecord": {
            "Timestamp": eTimes + '',
            "EmpID": this.empIds,
            "EmpName": this.empNames,
            "Type": tyid,
            "KeySerial": KeySerial,
            "KeyType": "273",
            "Account": this.accountNameOnline,
            "Role": "admin",
            "Result": sults + '',
            "ResultDesc": redusl,
          },
        },
      };
      let daJsons = {
        "Root": {
          "LogType": "50",
          "LogRecord": {
            "Timestamp": eTimes + '',
            "EmpID": this.empIds,
            "EmpName": this.empNames,
            "Type": tyid,
            "KeySerial": KeySerial,
            "KeyType": "273",
            "Account": this.accountNameOnline,
            "Role": "user",
            "Result": sults + '',
            "ResultDesc": redusl,
          },
        },
      };
      that.$postForJson("/aqdl/auditlog/setlogrecord", daJsons).then((res) => {
        console.log(res);
        that.$postForJson("/aqdl/auditlog/setlogrecord", daJson).then((res) => {
          console.log(res);
          if (tyid == '292' && redusl == '成功') {
            // that.setlogrlist("296", '0', "成功");
          } else if (tyid == '292' && redusl == '失败') {
            // that.setlogrlist("296", '1', "失败");
          }
          if (tyid == '296' && redusl == '成功') {
            that.datalists();
          }
          if (tyid == '293' && redusl == '成功') {
            that.datalists();
          }
        });
      });
      })
    },
    // 关闭
    bangdliangshu() {
      this.showDetailinagbangd = false;
    },
    // 绑定用户
    bangdying() {
      this.showDetailinagbangd = false;
      this.showDetailDialog = true;
    },
    // 绑定终端
    bnagsdzhus() {
      this.showDetailinagbangd = false;
      this.showbangzduanlog = true;
    },
    bangdlzhongduas() {
      this.showbangzduanlog = false;
    },
    zhonduqures() {
      this.showbangzduanlog = false;
    },
    showjiebansgsdsz() {
      this.showjiebangsz = false;
    },
    // pin码修改
    editpins() {
      this.absopindlosa = true;
    },
    pinabsoclis() {
      this.absopindlosa = false;
      this.$message({
        message: "修改成功!",
        type: "success",
      });
    },
    /**
     * 设置表格的高度
     */
    setTableHeight() {
      let clientHeiht =
        window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 160;
    },
    /**
     * 表格序号
     * @param index {Number} 表格索引值
     * @return currentIndex 处理后的表格序号
     */
    indexMethod(index) {
      let currentIndex;
      if (this.pageNum === 1) {
        currentIndex = index + this.pageNum;
      } else {
        let page = (this.pageNum - 1) * this.pageSize;
        currentIndex = index + 1 + page;
      }
      return currentIndex;
    },

    /**
     * 切换每页条数
     */
    handleSizeChange(value) {
      this.pageSize = value;
    },

    /**
     * 切换页码
     */
    handlePageChange(value) {
      this.pageNum = value;
    },
    /**
     * 搜索按钮
     */
    handelSearch() {
      this.datalists();
      this.multipleSelection = [];
    },
    deldngd() {
      this.$confirm("确认是否删除？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            message: "删除成功!",
            type: "success",
          });
        })
        .catch((_) => { });
    },
    cobnabagsata(add, data) {
      // this.showjiebangsz = true;
      this.butzbangds("1", data);
    },
    butzbangds(d, data) {
      this.showjiebangsz = false;
      if (d == "1") {
        console.log(data);
        if (data.status == "未绑定") {
          this.$message({
            message: "请先绑定!",
            type: "warning",
          });
          return false;
        }
        let datas = {};
        datas.keyId = data.keyId;
        datas.keyType = data.keyType;
        datas.user = data.user;
        datas.onlyId = data.onlyId;
        datas.empUser = data.empUserId;
        // datas.empUserName = data.empUserName;
        // datas.empUserAccount = data.empUserAccount;
        console.log(datas);
        this.$confirm("确认是否解绑用户？", "提示", {
          confirmButtonText: "确 定",
          cancelButtonText: "取 消",
          type: "warning",
        })
          .then(() => {
            this.$postForJson("/aqdl/bjtx/unbind", datas).then((res) => {
              console.log(res);
              if (res.data.errorcode == "0") {
                this.$message({
                  message: "解绑成功!",
                  type: "success",
                });
                // this.datalists();
                this.setlogrlist("293", res.data.errorcode, "成功",);
              } else {
                this.$message({
                  message: "解绑失败!",
                  type: "error",
                });
                this.setlogrlist("293", res.data.errorcode, "失败");
              }
            });
          })
          .catch((_) => { });
      } else {
        this.$confirm("确认是否解绑终端？", "提示", {
          confirmButtonText: "确 定",
          cancelButtonText: "取 消",
          type: "warning",
        })
          .then(() => {
            this.$message({
              message: "解绑成功!",
              type: "success",
            });
          })
          .catch((_) => { });
      }
    },
    // 导出回调
    theImportCallback(val) {
      if (val.success) {
        const h = this.$createElement;
        this.$msgbox({
          title: "消息",
          message: h("div", null, [
            h("p", { fontSize: "18px" }, "上传结果："),
            h("p", null, `共上传${val.results.totalNum}条`),
            h(
              "p",
              { style: { color: "#67C23A" } },
              `成功${val.results.succeedNum}条`
            ),
            h(
              "p",
              { style: { color: "#F56C6C" } },
              `失败${val.results.errorNum}条`
            ),
          ]),
          showCancelButton: false,
          confirmButtonText: "确定",
          type: "warning",
        }).then(() => {
          console.log(111);
          // this.getTableInfo(this.currentPage, this.pagesize);
        });
      }
    },
    absopinddlosa() { },
    // 导出
    exprdoagods() {
      //  $("#downloadFile").attr("src", window.root + url);
    },
  },

  filters: {},
};
</script>

<style scoped>
@import "../../assets/css/commonTable.css";

.alarm-row {
  width: 80%;
}

.icon-shenjiguanli {
  font-size: 14px;
}

.tip-area {
  padding: 8px 16px;
  background-color: #ecf8ff;
  border-radius: 4px;
  border-left: 5px solid #50bfff;
  margin: 0 0 20px 0;
}

.search-area {
  display: flex;
}

.current-page .search-area .search-form {
  width: 100%;
}

.dengshus .awas {
  width: 60%;
  margin: 20px auto;
}

.bamnhds {
  display: flex;
  border-top: 2px solid #ccc;
}

.zhondbsts {
  /* border-top: 2px solid #ccc; */
  display: flex;
  flex-direction: column;
}

.bamnhds .liebs {
  width: 20%;
  border-right: 1px solid #ccc;
}

.bamnhds .biaogri {
  width: 75%;
}

.bamnhds .biaogri .sos {
  width: 30%;
  margin: 10px;
  float: right;
}

.el-dialog__body {
  padding: 0;
}

:deep(.el-dialog__footer) {
  text-align: center;
}

:deep(.el-tree, .leftCol) {
  background: #fff;
}

.zhondbsts .shaixun {
  border-bottom: 1px solid #ccc;
  padding: 10px;
  padding-left: 38%;
  border-top: 1px solid #ccc;
}

.zhondbsts .sous {
  width: 30%;
  display: flex;
  padding: 10px;
  margin-left: 70%;
}

.zhondbsts .baiosh {
  border-top: 1px solid #ccc;
}

.yngsds {
  margin-bottom: 10px;
}

.danhus {
  display: flex;
  flex-direction: column;
}

.yihangs {
  margin-left: 30px;
  margin-bottom: 10px;
}

.el-select,
.el-input,
el-date-picker {
  width: 100%;
}
</style>
